$(document).ready(function(){

  
	$('#ajax_form').find('#username').blur(function() {
    
      var username=$("#username").val();
       
      $.post('http://localhost/MVC_ICE/index.php/ajax/username_taken',
			{ 'cedula':username },

			// when the Web server responds to the request
			function(result) {
				// clear any message that may have already been written
				$('#bad_username').replaceWith('');
				
				// if the result is TRUE write a message to the page
				if (result) {
					//alert(result);
					$('#cedula').after('<div id="bad_username" style="color:red;">' +
					  '<p>(That Username is already taken. Please choose another.)</p></div>');
				}
			}
		);
	 /*
	  $.ajax({
        type: "POST",
        url: "/index.php/ajax/username_taken",
        dataType: "json",
        data: "username="+username,
        cache:false,
        success: 
          function(data){
			alert('hola');
            //$("#form_message").html(data.message).css({'background-color' : data.bg_color}).fadeIn('slow'); 
          }
        
        });*/
    });
	
  $("#login_submit").click( 
  
    function(){
    
        var username=$("#username").val();
        var password=$("#password").val();
     
        $.ajax({
        type: "POST",
        url: "/index.php/ajax/post_action",
        dataType: "json",
        data: "username="+username+"&password="+password,
        cache:false,
        success: 
          function(data){
			//alert('holaaaaaaaaaaaa');
            $("#form_message").html(data.message).css({'background-color' : data.bg_color}).fadeIn('slow'); 
          }
        
        });

      return false;

    });
});